package com.nobuyme.box.downUpdata;

/**
 * Created by Administrator on 2017/3/1.
 */


import android.os.Handler;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public abstract class CallbackUTF8 implements Callback {
    Handler mHandler;

    public CallbackUTF8(Handler mHandler) {
        super();
        this.mHandler = mHandler;
    }

    public CallbackUTF8(){

    }

    @Override
    public void onFailure(Call arg0, IOException arg1) {
        onFailure(arg1);
    }

    @Override
    public void onResponse(Call arg0, final Response arg1) throws IOException {
        if (mHandler != null){
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    try {
                        onTResponse(arg1, arg1.body().string());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
        }else{
            onTResponse(arg1, arg1.body().string());
        }
    }


    public abstract void onTResponse(Response response, String utf8);

    public abstract void onFailure(Exception arg1);
}